package com.vnp.cooking;

import java.util.ArrayList;
import java.util.jar.Attributes.Name;

import com.google.analytics.tracking.android.Fields;
import com.google.analytics.tracking.android.MapBuilder;
import com.vnp.cooking.adapter.DetailDacDiemAdapter;
import com.vnp.cooking.adapter.DetailLoaiMonAdapter;
import com.vnp.cooking.bean.ObjAttribute;
import com.vnp.cooking.utils.PreferenceHelper;

import android.os.Bundle;
import android.preference.Preference;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class DetailLoaiMonActivity extends Activity implements OnItemClickListener,OnClickListener{

	ImageButton btnBack;
	ListView listDetailLoaimon; 
	DetailLoaiMonAdapter adapter;
	ArrayList<ObjAttribute> listDetails = new ArrayList<ObjAttribute>();
	TextView titleDetail;
	String title;
	String alias;
	PreferenceHelper preferenceHelper;
	// animation click
	Animation animTranslate;
	private static final String SCREEN_LABEL = "Chi tiet loai mon screen";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_detail_loai_mon);
		preferenceHelper = new PreferenceHelper(this);
		
		title = getIntent().getStringExtra("title");
		alias = getIntent().getStringExtra("alias");
		
		try {
			listDetails = getIntent().getParcelableArrayListExtra("listDetail");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
				
		
		btnBack = (ImageButton) findViewById(R.id.btn_back);
		titleDetail = (TextView) findViewById(R.id.txt_detail_loaimon_title);
		listDetailLoaimon = (ListView) findViewById(R.id.list_detai_loaimon);
		adapter = new DetailLoaiMonAdapter(this, listDetails);
		
		init();
		ApplicationContext.getGaTracker().set(Fields.SCREEN_NAME, SCREEN_LABEL);
	}
	
	@Override
	public void onStart() {
		super.onStart();
		ApplicationContext.getGaTracker().send(MapBuilder.createAppView().build());
	}

	@Override
	public void onStop() {
		super.onStop();
	}

	
	void init() {
		animTranslate = AnimationUtils.loadAnimation(this, R.anim.button_click_animation);
		titleDetail.setText(title);
		btnBack.setOnClickListener(this);
		try {
			listDetailLoaimon.setAdapter(adapter);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		listDetailLoaimon.setOnItemClickListener(this);
	}


	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			closeActivity();
			break;

		default:
			break;
		}
	}


	@Override
	public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
		Intent t = new Intent(DetailLoaiMonActivity.this, ResultLoaimonActivity.class);
		t.putExtra("alias", alias);
		t.putExtra("title", listDetails.get(position).getName());
		t.putExtra("aliasDetail", listDetails.get(position).getAlias());
		startActivity(t);
		overridePendingTransition(R.anim.open_next, R.anim.close_main);
		
	}
	
	void gotoResult() {
		
	}
	
	void closeActivity(){
		finish();
		overridePendingTransition(R.anim.open_main, R.anim.close_next);
	}


	@Override
	public void onBackPressed() {
		closeActivity();
	}


}
